
package com.eva.android.shortvideo;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.x52im.rbchat.R;

/**
 * 当短视频未成功加载时显示的UI.
 * <p>
 * 独立出本类的唯一原因，是为了让主类 {@link ShortVideoPlayerActivity} 的
 * 代码保持简洁，易于理解和维护，仅此而已，别无它用。
 * </p>
 *
 * @author Jack Jiang
 * @since 5.1
 */
class NoVideoWrapper {
    private ShortVideoPlayerActivity parentActivity = null;

    private ViewGroup layoutOfNoVideo = null;
    private ImageView viewIcon = null;
    private ProgressBar progressForDownload = null;
    private TextView viewHint = null;

    public NoVideoWrapper(ShortVideoPlayerActivity parentActivity) {
        this.parentActivity = parentActivity;
        initViews();
    }

    private void initViews() {
        layoutOfNoVideo = (ViewGroup) parentActivity.findViewById(R.id.common_short_video_player_ac_noVideoLL);
        viewIcon = (ImageView) parentActivity.findViewById(R.id.common_short_video_player_ac_viewHintIco);
        progressForDownload = (ProgressBar) parentActivity.findViewById(R.id.common_short_video_player_ac_progressBar);
        viewHint = (TextView) parentActivity.findViewById(R.id.common_short_video_player_ac_viewHintText);
    }

    public NoVideoWrapper setVisible(boolean visible) {
        if (visible) {
            parentActivity.layoutVideoView.setVisibility(View.GONE);
            layoutOfNoVideo.setVisibility(View.VISIBLE);
        } else
            layoutOfNoVideo.setVisibility(View.GONE);
        return this;
    }

    public NoVideoWrapper setVisible(boolean visible, boolean progressVisible) {
        setVisible(visible);

        if (progressVisible)
            progressForDownload.setVisibility(View.VISIBLE);
        else
            progressForDownload.setVisibility(View.GONE);
        return this;
    }

    public NoVideoWrapper setProgress(int progressOf100) {
        progressForDownload.setProgress(progressOf100);
        return this;
    }

    public NoVideoWrapper setText(String text) {
        viewHint.setText(text);
        return this;
    }

    public NoVideoWrapper setIcon(int resId) {
        viewIcon.setImageResource(resId);
        return this;
    }
}